/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.momarketing.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boxin.ims.modules.momarketing.dao.ProjectMenuDao;
import com.boxin.ims.modules.momarketing.entity.ProjectMenu;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;

/**
 * 微网站菜单导航Service
 * @author Jakemanse
 * @version 2013-11-27
 */
@Component
@Transactional(readOnly = true)
public class ProjectMenuService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ProjectMenuService.class);
	
	@Autowired
	private ProjectMenuDao projectMenuDao;
	
	public ProjectMenu get(Long id) {
		return projectMenuDao.findOne(id);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-11-27  上午10:44:12
	 * @function <p> 查询所有菜单  </p>
	 * @return
	 */
	public List<ProjectMenu> getAllDisplayMenus() {
		DetachedCriteria dc = projectMenuDao.createDetachedCriteria();
		dc.addOrder(Order.desc("sort"));
		return projectMenuDao.find( dc);
	}
	
	
	
	public Page<ProjectMenu> find(Page<ProjectMenu> page, ProjectMenu projectMenu) {
		DetachedCriteria dc = projectMenuDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(projectMenu.getName())){
			dc.add(Restrictions.like("name", "%"+projectMenu.getName()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return projectMenuDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ProjectMenu projectMenu) {
		projectMenuDao.save(projectMenu);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		projectMenuDao.deleteById(id);
	}
	
}
